import wx
class MyFrame(wx.Frame):
    def __init__(self,parent,id):
        wx.Frame.__init__(self,parent,id,title="创建TextCtrl类",pos=(100,100),size=(400,300))
        #创建面板
        panel=wx.Panel(self,-1)
        #创建文本和输入框
        title=wx.StaticText(panel,label='请输入用户名和密码')
        label_user=wx.StaticText(panel,label='用户名')
        text_user=wx.TextCtrl(panel,style=wx.TE_LEFT)
        label_pwd=wx.StaticText(panel,label='密码')
        text_pwd=wx.TextCtrl(panel,style=wx.TE_PASSWORD)
        #创建“确认”和“取消”按钮
        bt_confirm=wx.Button(panel,label='确认')
        bt_cancel=wx.Button(panel,label='取消')
        #添加容器，容器中控件横向排列
        hsizer_user=wx.BoxSizer(wx.HORIZONTAL)
        hsizer_user.Add(label_user,proportion=0,flag=wx.ALL,border=5)
        hsizer_user.Add(text_user,proportion=1,flag=wx.ALL,border=5)
        hsizer_pwd=wx.BoxSizer(wx.HORIZONTAL)
        hsizer_pwd.Add(label_pwd,proportion=0,flag=wx.ALL,border=5)
        hsizer_pwd.Add(text_pwd,proportion=1,flag=wx.ALL,border=5)
        hsizer_button=wx.BoxSizer(wx.HORIZONTAL)
        hsizer_button.Add(bt_confirm,proportion=0,flag=wx.ALIGN_CENTER,border=5)
        hsizer_button.Add(bt_cancel,proportion=1,flag=wx.ALIGN_CENTER,border=5)
        #添加容器，容器中的控件纵向排列
        vsizer_all=wx.BoxSizer(wx.VERTICAL)
        vsizer_all.Add(title,proportion=0,flag=wx.BOTTOM|wx.TOP|wx.ALIGN_CENTER,border=15)
        vsizer_all.Add(hsizer_user,proportion=0,flag=wx.EXPAND|wx.LEFT|wx.RIGHT,border=45)
        vsizer_all.Add(hsizer_pwd,proportion=0,flag=wx.EXPAND|wx.LEFT|wx.RIGHT,border=45)
        vsizer_all.Add(hsizer_button,proportion=0,flag=wx.ALIGN_CENTER|wx.TOP,border=15)
        panel.SetSizer(vsizer_all)
if __name__=='__main__':
    app=wx.App()
    frame=MyFrame(parent=None,id=-1)
    frame.Show()
    app.MainLoop()